package test4.menus;

import com.jme3.niftygui.NiftyJmeDisplay;
import de.lessvoid.nifty.EndNotify;
import de.lessvoid.nifty.Nifty;
import de.lessvoid.nifty.screen.Screen;
import de.lessvoid.nifty.screen.ScreenController;

public class MainMenuManager implements ScreenController {

    private Nifty nifty;
    private NiftyJmeDisplay niftyDisplay;
    private Screen screen;

    public void startNifty(NiftyJmeDisplay nDsp) {
        this.niftyDisplay = nDsp;
        nifty = niftyDisplay.getNifty();
        nifty.fromXml("/src/test4/menus/main.xml", "start");
    }

    public void interaction(String arg) {
        String xmlFile = "/src/test4/menus/" + arg + ".xml";
        nifty.fromXml(xmlFile, "start");
    }

    public void quit() {
        System.out.println("popup creating");
        nifty.createPopup("popupExit");
        nifty.showPopup(screen, "popupExit", null);
    }

    public void popupExit(final String exit) {
        nifty.closePopup("popupExit", new EndNotify() {
          public void perform() {
            if ("yes".equals(exit)) {
              nifty.setAlternateKey("fade");
              nifty.exit();
              System.exit(0);
            }
          }
        });
    }

    public void bind(Nifty newNifty, Screen newScreen) {
        this.nifty = newNifty;
        this.screen = newScreen;
    }

    public void onStartScreen() {

    }

    public void onEndScreen() {

    }

    public NiftyJmeDisplay getNiftyJmeDisplay() {
        return this.niftyDisplay;
    }

}
